<?php
/**
 * @filename:					PlaceDistrictAction.class.php
 * @desc:						寄存区、排模块
 *
 * @author: 					张召
 * @copyright:					winzzhao@sina.com
 * @date:						2011-05-05
 */


class PlaceDistrictAction extends CommonAction
{

    /**
    * 查看寄存区的信息
    */
	public function index(){
		$PlaceDistrict = new PlaceDistrictModel();
       // $Place = $PlaceDistrict->select();
       // dump($Place);die;

		if(isset($_REQUEST['pid']) && !empty($_REQUEST['pid'])){
			$this->assign('tag', L('list_sub_PlaceDistrict'));
			$map = array('pid' => $_REQUEST['pid']);
			$crumb_info = array(
				array('uri' => '__URL__', 'title' => L('PlaceDistrict_manage'), 'sort' => C('CRUMB_DEFAULT')),
				array('uri' => '__URL__/index/pid/' . $_REQUEST['pid'], 'title' => L('list_sub_PlaceDistrict'), 'sort' => C('CRUMB_LAST') ),
			);
			$this->_action_link = array(
				array('uri' => '__URL__/index', 'title' => L('list_PlaceDistrict')),
				array('uri' => '__URL__/add/pid/' . $_REQUEST['pid'], 'title' => L('add_PlaceDistrict_level')),
			);
			$this->assign('add_PlaceDistrict', L('add_PlaceDistrict_level'));
		}else{
			$this->assign('tag', L('list_PlaceDistrict'));
			$map = array('level' => 2);
			$crumb_info = array(
				array('uri' => '__URL__', 'title' => L('PlaceDistrict_manage'), 'sort' => C('CRUMB_LAST')),
			);
			$this->_action_link = array(
				array('uri' => '__URL__/add', 'title' => L('add_PlaceDistrict')),
			);
			$this->assign('add_PlaceDistrict', L('add_PlaceDistrict'));
		}

		if (! empty ( $PlaceDistrict )) {
			$this->_list ( $PlaceDistrict, $map );
		}

		$this->_mergeCrumbInfo($crumb_info);
		$this->assign('crumb_info', $this->_crumb_info);
		$this->assign('action_link', $this->_action_link);
		$this->display();
		return;
	}

	public function add(){
		//获取父节点id
		if(isset($_REQUEST['pid']) && !empty($_REQUEST['pid'])){
			$parent_id = $_REQUEST['pid'];
			$crumb_info = array(
				array('uri' => '__URL__', 'title' => L('PlaceDistrict_manage'), 'sort' => C('CRUMB_DEFAULT')),
				array('uri' => '__URL__/add/pid/' . $parent_id, 'title' => L('addsub'), 'sort' => C('CRUMB_LAST')),
			);
			$this->_mergeCrumbInfo($crumb_info);

			$this->_action_link = array(
			array('uri' => '__URL__/index/pid/' . $parent_id, 'title' => L('list_sub_PlaceDistrict')),
			);
		}else{
			$crumb_info = array(
				array('uri' => '__URL__', 'title' => L('PlaceDistrict_manage'), 'sort' => C('CRUMB_DEFAULT')),
				array('uri' => '__URL__/add', 'title' => L('add_PlaceDistrict'), 'sort' => C('CRUMB_LAST')),
			);
			$this->_mergeCrumbInfo($crumb_info);

			$this->_action_link = array(
			array('uri' => '__URL__/index/', 'title' => L('list_PlaceDistrict')),
			);
			$PlaceDistrict = new PlaceDistrictModel();
			$rootPlaceDistrictId = $PlaceDistrict->getRootPlaceDistrictId();
			$parent_id = $rootPlaceDistrictId;
		}

		$this->assign('add_PlaceDistrict', L('add_PlaceDistrict'));
		$this->assign('crumb_info', $this->_crumb_info);
		$this->assign('action_link', $this->_action_link);

		$this->assign('parent_id', $parent_id);
		parent::add();
	}

	public function edit(){
		$id = $_REQUEST['id'];
		$crumb_info = array(
			array('uri' => '__URL__', 'title' => L('PlaceDistrict_manage'), 'sort' => C('CRUMB_DEFAULT')),
			array('uri' => '__URL__/edit/id/' . $id, 'title' => L('edit_PlaceDistrict'), 'sort' => C('CRUMB_LAST')),
		);

		$this->_mergeCrumbInfo($crumb_info);
		$this->_action_link = array(array('uri' => '__URL__/index', 'title' => L('list_PlaceDistrict')),
		);

		$this->assign('crumb_info', $this->_crumb_info);
		$this->assign('action_link', $this->_action_link);


		$PlaceDistrict = new PlaceDistrictModel();
		$vo = $PlaceDistrict->getById ( $id );
		$this->assign('parent_id', $vo['pid']);
		$this->assign ( 'vo', $vo );

		$this->display ();
	}

	public function insert(){
		$PlaceDistrict = new PlaceDistrictModel();
		$level = $PlaceDistrict->getLevel($_POST['pid']);
		$_POST['level'] = $level;

		parent::insert();
	}

	private function _getGroupList()
	{
		$Group = M('Group');
		$list  = $Group->where('status=1')->field('id, title')->select();
		return $list;
	}

    /**
    * 删除寄存区
    */
    public function delete()
    {
       parent::delete();
    }

}

?>